﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;

namespace QMERP.Infrastructure.EFCore.Mappings
{
    public class PurchaseOrderMapping : IEntityTypeConfiguration<PurchaseOrder>
    {
        public void Configure(EntityTypeBuilder<PurchaseOrder> builder)
        {
            builder.HasQueryFilter(x => x.IsEnable);
            builder.Property(x => x.Number).HasMaxLength(30);
            builder.Property(x => x.CustomerOrderNumber).HasMaxLength(30);
            //builder.Property(x => x.SequenceNumber).IsRequired(false).HasMaxLength(50);
            builder.Property(x => x.Status).HasMaxLength(50);
            builder.Property(x => x.CheckedBy).IsRequired(false);
            builder.Property(x => x.CheckedByName).HasMaxLength(50).IsRequired(false);
            builder.Property(x => x.CheckedOn).IsRequired(false).HasColumnType("datetime");
            builder.Property(x => x.FinishedBy).IsRequired(false);
            builder.Property(x => x.FinishedByName).HasMaxLength(50).IsRequired(false);
            builder.Property(x => x.FinishedOn).IsRequired(false).HasColumnType("datetime");
            builder.Property(x => x.Remark).IsRequired(false).HasMaxLength(500);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.Number);
            builder.HasIndex(x => x.CustomerOrderNumber);
            //builder.HasIndex(x => x.SequenceNumber);
            builder.HasIndex(x => x.Status);
            builder.HasIndex(x => x.CreatedOn).IsDescending();
            builder.HasIndex(x => x.CheckedOn).IsDescending();
            builder.HasIndex(x => x.FinishedOn).IsDescending();
        }
    }
}
